{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这是我的第一个代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入pd和np两个库，用于数据处理和科学计算\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "# 设置列不限制数量\n",
    "pd.set_option('display.max_columns', None)\n",
    "# pd.set_option('display.max_rows',None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Encoding: ascii, Confidence: 1.0\n"
     ]
    }
   ],
   "source": [
    "# 检测csv文件的编码格式，为数据导入提供编码正确性保障\n",
    "import chardet\n",
    "\n",
    "def check_encoding(filename):\n",
    "    rawdata = open(filename, 'rb').read()\n",
    "    result = chardet.detect(rawdata)# 安装相应的环境包\n",
    "    encoding = result['encoding']\n",
    "    confidence = result['confidence']\n",
    "    return encoding, confidence\n",
    "\n",
    "file_path = '000001.csv'# 添加文件路径\n",
    "encoding, confidence = check_encoding(file_path)\n",
    "print(f\"Encoding: {encoding}, Confidence: {confidence}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025/8/25</td>\n",
       "      <td>3825.759</td>\n",
       "      <td>3848.163</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3839.972</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025/8/26</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3871.471</td>\n",
       "      <td>3888.599</td>\n",
       "      <td>3859.758</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025/8/27</td>\n",
       "      <td>3868.382</td>\n",
       "      <td>3869.612</td>\n",
       "      <td>3887.198</td>\n",
       "      <td>3800.350</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025/8/28</td>\n",
       "      <td>3800.35</td>\n",
       "      <td>3796.711</td>\n",
       "      <td>3845.087</td>\n",
       "      <td>3761.422</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025/8/29</td>\n",
       "      <td>3843.597</td>\n",
       "      <td>3842.823</td>\n",
       "      <td>3867.606</td>\n",
       "      <td>3839.206</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Day  Preclose      Open   Highest    Lowest     Close\n",
       "0     1990/12/19              96.050    99.980    95.790    99.980\n",
       "1     1990/12/20     99.98   104.300   104.390    99.980   104.390\n",
       "2     1990/12/21    104.39   109.070   109.130   103.730   109.130\n",
       "3     1990/12/24    109.13   113.570   114.550   109.130   114.550\n",
       "4     1990/12/25    114.55   120.090   120.250   114.550   120.250\n",
       "...          ...       ...       ...       ...       ...       ...\n",
       "8468   2025/8/25  3825.759  3848.163  3883.562  3839.972  3883.562\n",
       "8469   2025/8/26  3883.562  3871.471  3888.599  3859.758  3868.382\n",
       "8470   2025/8/27  3868.382  3869.612  3887.198  3800.350  3800.350\n",
       "8471   2025/8/28   3800.35  3796.711  3845.087  3761.422  3843.597\n",
       "8472   2025/8/29  3843.597  3842.823  3867.606  3839.206  3857.927\n",
       "\n",
       "[8473 rows x 6 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入数据的代码\n",
    "data = pd.read_csv('000001.csv') # 这一句是导入代码数据的命令\n",
    "data # 让我看看数据是什么样子"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " 需要注意的是 \n",
    " Jupyter Notebook默认只输出或者打印最后一行命令，如果你需要所有中间步骤的结果都输出的话，需要添加如下的代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.core.interactiveshell import InteractiveShell# 配置IPython交互式环境\n",
    "InteractiveShell.ast_node_interactivity = 'all'# 保证每个单元格中的所有语句结果都被依次输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025/8/25</td>\n",
       "      <td>3825.759</td>\n",
       "      <td>3848.163</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3839.972</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025/8/26</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3871.471</td>\n",
       "      <td>3888.599</td>\n",
       "      <td>3859.758</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025/8/27</td>\n",
       "      <td>3868.382</td>\n",
       "      <td>3869.612</td>\n",
       "      <td>3887.198</td>\n",
       "      <td>3800.350</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025/8/28</td>\n",
       "      <td>3800.35</td>\n",
       "      <td>3796.711</td>\n",
       "      <td>3845.087</td>\n",
       "      <td>3761.422</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025/8/29</td>\n",
       "      <td>3843.597</td>\n",
       "      <td>3842.823</td>\n",
       "      <td>3867.606</td>\n",
       "      <td>3839.206</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Day  Preclose      Open   Highest    Lowest     Close\n",
       "0     1990/12/19              96.050    99.980    95.790    99.980\n",
       "1     1990/12/20     99.98   104.300   104.390    99.980   104.390\n",
       "2     1990/12/21    104.39   109.070   109.130   103.730   109.130\n",
       "3     1990/12/24    109.13   113.570   114.550   109.130   114.550\n",
       "4     1990/12/25    114.55   120.090   120.250   114.550   120.250\n",
       "...          ...       ...       ...       ...       ...       ...\n",
       "8468   2025/8/25  3825.759  3848.163  3883.562  3839.972  3883.562\n",
       "8469   2025/8/26  3883.562  3871.471  3888.599  3859.758  3868.382\n",
       "8470   2025/8/27  3868.382  3869.612  3887.198  3800.350  3800.350\n",
       "8471   2025/8/28   3800.35  3796.711  3845.087  3761.422  3843.597\n",
       "8472   2025/8/29  3843.597  3842.823  3867.606  3839.206  3857.927\n",
       "\n",
       "[8473 rows x 6 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             Day  Preclose      Open   Highest    Lowest     Close\n",
      "0     1990/12/19              96.050    99.980    95.790    99.980\n",
      "1     1990/12/20     99.98   104.300   104.390    99.980   104.390\n",
      "2     1990/12/21    104.39   109.070   109.130   103.730   109.130\n",
      "3     1990/12/24    109.13   113.570   114.550   109.130   114.550\n",
      "4     1990/12/25    114.55   120.090   120.250   114.550   120.250\n",
      "...          ...       ...       ...       ...       ...       ...\n",
      "8468   2025/8/25  3825.759  3848.163  3883.562  3839.972  3883.562\n",
      "8469   2025/8/26  3883.562  3871.471  3888.599  3859.758  3868.382\n",
      "8470   2025/8/27  3868.382  3869.612  3887.198  3800.350  3800.350\n",
      "8471   2025/8/28   3800.35  3796.711  3845.087  3761.422  3843.597\n",
      "8472   2025/8/29  3843.597  3842.823  3867.606  3839.206  3857.927\n",
      "\n",
      "[8473 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "data = pd.read_csv('000001.csv') # 这一句是导入代码数据的命令\n",
    "data\n",
    "print(data)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "了解变量的格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "打印数据框的列名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['Day', 'Preclose', 'Open', 'Highest', 'Lowest', 'Close'], dtype='object')\n"
     ]
    }
   ],
   "source": [
    "print(data.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Day' 'Preclose' 'Open' 'Highest' 'Lowest' 'Close']\n"
     ]
    }
   ],
   "source": [
    "print(data.columns.values)# 将列名以数组形式输出"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "选择某一列，下面两个代码的区别在于：上面采用字典键取值逻辑，兼容性更强；下面采用对象属性取值逻辑，书写更简洁"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       1990/12/19\n",
       "1       1990/12/20\n",
       "2       1990/12/21\n",
       "3       1990/12/24\n",
       "4       1990/12/25\n",
       "           ...    \n",
       "8468     2025/8/25\n",
       "8469     2025/8/26\n",
       "8470     2025/8/27\n",
       "8471     2025/8/28\n",
       "8472     2025/8/29\n",
       "Name: Day, Length: 8473, dtype: object"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Day']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       1990/12/19\n",
       "1       1990/12/20\n",
       "2       1990/12/21\n",
       "3       1990/12/24\n",
       "4       1990/12/25\n",
       "           ...    \n",
       "8468     2025/8/25\n",
       "8469     2025/8/26\n",
       "8470     2025/8/27\n",
       "8471     2025/8/28\n",
       "8472     2025/8/29\n",
       "Name: Day, Length: 8473, dtype: object"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.Day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025/8/25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025/8/26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025/8/27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025/8/28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025/8/29</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Day\n",
       "0     1990/12/19\n",
       "1     1990/12/20\n",
       "2     1990/12/21\n",
       "3     1990/12/24\n",
       "4     1990/12/25\n",
       "...          ...\n",
       "8468   2025/8/25\n",
       "8469   2025/8/26\n",
       "8470   2025/8/27\n",
       "8471   2025/8/28\n",
       "8472   2025/8/29\n",
       "\n",
       "[8473 rows x 1 columns]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[['Day']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "明确区分不同列提取方式返回的数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(data['Day'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(data[['Day']])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "选择多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025/8/25</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025/8/26</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025/8/27</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025/8/28</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025/8/29</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Day     Close\n",
       "0     1990/12/19    99.980\n",
       "1     1990/12/20   104.390\n",
       "2     1990/12/21   109.130\n",
       "3     1990/12/24   114.550\n",
       "4     1990/12/25   120.250\n",
       "...          ...       ...\n",
       "8468   2025/8/25  3883.562\n",
       "8469   2025/8/26  3868.382\n",
       "8470   2025/8/27  3800.350\n",
       "8471   2025/8/28  3843.597\n",
       "8472   2025/8/29  3857.927\n",
       "\n",
       "[8473 rows x 2 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[['Day','Close']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "选择行数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "      <td></td>\n",
       "      <td>96.05</td>\n",
       "      <td>99.98</td>\n",
       "      <td>95.79</td>\n",
       "      <td>99.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.30</td>\n",
       "      <td>104.39</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.07</td>\n",
       "      <td>109.13</td>\n",
       "      <td>103.73</td>\n",
       "      <td>109.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.57</td>\n",
       "      <td>114.55</td>\n",
       "      <td>109.13</td>\n",
       "      <td>114.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.09</td>\n",
       "      <td>120.25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1990/12/26</td>\n",
       "      <td>120.25</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.27</td>\n",
       "      <td>120.25</td>\n",
       "      <td>125.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1990/12/27</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.28</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1990/12/28</td>\n",
       "      <td>125.28</td>\n",
       "      <td>126.39</td>\n",
       "      <td>126.45</td>\n",
       "      <td>125.28</td>\n",
       "      <td>126.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1990/12/31</td>\n",
       "      <td>126.45</td>\n",
       "      <td>126.56</td>\n",
       "      <td>127.61</td>\n",
       "      <td>126.48</td>\n",
       "      <td>127.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1991/1/2</td>\n",
       "      <td>127.61</td>\n",
       "      <td>127.61</td>\n",
       "      <td>128.84</td>\n",
       "      <td>127.61</td>\n",
       "      <td>128.84</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Day  Preclose    Open  Highest  Lowest   Close\n",
       "0  1990/12/19             96.05    99.98   95.79   99.98\n",
       "1  1990/12/20     99.98  104.30   104.39   99.98  104.39\n",
       "2  1990/12/21    104.39  109.07   109.13  103.73  109.13\n",
       "3  1990/12/24    109.13  113.57   114.55  109.13  114.55\n",
       "4  1990/12/25    114.55  120.09   120.25  114.55  120.25\n",
       "5  1990/12/26    120.25  125.27   125.27  120.25  125.27\n",
       "6  1990/12/27    125.27  125.27   125.28  125.27  125.28\n",
       "7  1990/12/28    125.28  126.39   126.45  125.28  126.45\n",
       "8  1990/12/31    126.45  126.56   127.61  126.48  127.61\n",
       "9    1991/1/2    127.61  127.61   128.84  127.61  128.84"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 该代码用于选择data数据框中的第0行到第9行（共10行），即通过切片操作选取前10行数据。\n",
    "data[0:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990/12/19</td>\n",
       "      <td></td>\n",
       "      <td>96.05</td>\n",
       "      <td>99.98</td>\n",
       "      <td>95.79</td>\n",
       "      <td>99.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990/12/20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.30</td>\n",
       "      <td>104.39</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990/12/21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.07</td>\n",
       "      <td>109.13</td>\n",
       "      <td>103.73</td>\n",
       "      <td>109.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990/12/24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.57</td>\n",
       "      <td>114.55</td>\n",
       "      <td>109.13</td>\n",
       "      <td>114.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990/12/25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.09</td>\n",
       "      <td>120.25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1990/12/26</td>\n",
       "      <td>120.25</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.27</td>\n",
       "      <td>120.25</td>\n",
       "      <td>125.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1990/12/27</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.28</td>\n",
       "      <td>125.27</td>\n",
       "      <td>125.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1990/12/28</td>\n",
       "      <td>125.28</td>\n",
       "      <td>126.39</td>\n",
       "      <td>126.45</td>\n",
       "      <td>125.28</td>\n",
       "      <td>126.45</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Day  Preclose    Open  Highest  Lowest   Close\n",
       "0  1990/12/19             96.05    99.98   95.79   99.98\n",
       "1  1990/12/20     99.98  104.30   104.39   99.98  104.39\n",
       "2  1990/12/21    104.39  109.07   109.13  103.73  109.13\n",
       "3  1990/12/24    109.13  113.57   114.55  109.13  114.55\n",
       "4  1990/12/25    114.55  120.09   120.25  114.55  120.25\n",
       "5  1990/12/26    120.25  125.27   125.27  120.25  125.27\n",
       "6  1990/12/27    125.27  125.27   125.28  125.27  125.28\n",
       "7  1990/12/28    125.28  126.39   126.45  125.28  126.45"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 该代码使用 iloc 按照行号和列号进行数据选择。\n",
    "# data.iloc[0:8, 0:6] 表示选取 data 数据框的第 0 行到第 7 行（共 8 行），\n",
    "# 以及第 0 列到第 5 列（共 6 列）的数据。\n",
    "data.iloc[0:8,0:6] #按行列号访问"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(109.07)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.at[2, 'Open']# 按行索引，列名访问"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2076    1168.91\n",
       "Name: Open, dtype: float64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用条件筛选来获取特定日期的开盘价\n",
    "data[data['Day'] == \"1999/4/16\"].Open"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "根据时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990-12-19</td>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990-12-20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990-12-21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990-12-24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990-12-25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025-08-25</td>\n",
       "      <td>3825.759</td>\n",
       "      <td>3848.163</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3839.972</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025-08-26</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3871.471</td>\n",
       "      <td>3888.599</td>\n",
       "      <td>3859.758</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025-08-27</td>\n",
       "      <td>3868.382</td>\n",
       "      <td>3869.612</td>\n",
       "      <td>3887.198</td>\n",
       "      <td>3800.350</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025-08-28</td>\n",
       "      <td>3800.35</td>\n",
       "      <td>3796.711</td>\n",
       "      <td>3845.087</td>\n",
       "      <td>3761.422</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025-08-29</td>\n",
       "      <td>3843.597</td>\n",
       "      <td>3842.823</td>\n",
       "      <td>3867.606</td>\n",
       "      <td>3839.206</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Day  Preclose      Open   Highest    Lowest     Close\n",
       "0    1990-12-19              96.050    99.980    95.790    99.980\n",
       "1    1990-12-20     99.98   104.300   104.390    99.980   104.390\n",
       "2    1990-12-21    104.39   109.070   109.130   103.730   109.130\n",
       "3    1990-12-24    109.13   113.570   114.550   109.130   114.550\n",
       "4    1990-12-25    114.55   120.090   120.250   114.550   120.250\n",
       "...         ...       ...       ...       ...       ...       ...\n",
       "8468 2025-08-25  3825.759  3848.163  3883.562  3839.972  3883.562\n",
       "8469 2025-08-26  3883.562  3871.471  3888.599  3859.758  3868.382\n",
       "8470 2025-08-27  3868.382  3869.612  3887.198  3800.350  3800.350\n",
       "8471 2025-08-28   3800.35  3796.711  3845.087  3761.422  3843.597\n",
       "8472 2025-08-29  3843.597  3842.823  3867.606  3839.206  3857.927\n",
       "\n",
       "[8473 rows x 6 columns]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将'day'列的字符串格式日期转换为Pandas的datetime类型\n",
    "# format='%Y/%m/%d' 指定了输入日期的格式：年/月/日\n",
    "data['Day'] = pd.to_datetime(data['Day'],format = '%Y/%m/%d')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025-08-29</td>\n",
       "      <td>3843.597</td>\n",
       "      <td>3842.823</td>\n",
       "      <td>3867.606</td>\n",
       "      <td>3839.206</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025-08-28</td>\n",
       "      <td>3800.35</td>\n",
       "      <td>3796.711</td>\n",
       "      <td>3845.087</td>\n",
       "      <td>3761.422</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025-08-27</td>\n",
       "      <td>3868.382</td>\n",
       "      <td>3869.612</td>\n",
       "      <td>3887.198</td>\n",
       "      <td>3800.350</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025-08-26</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3871.471</td>\n",
       "      <td>3888.599</td>\n",
       "      <td>3859.758</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025-08-25</td>\n",
       "      <td>3825.759</td>\n",
       "      <td>3848.163</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3839.972</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990-12-25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990-12-24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990-12-21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990-12-20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990-12-19</td>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Day  Preclose      Open   Highest    Lowest     Close\n",
       "8472 2025-08-29  3843.597  3842.823  3867.606  3839.206  3857.927\n",
       "8471 2025-08-28   3800.35  3796.711  3845.087  3761.422  3843.597\n",
       "8470 2025-08-27  3868.382  3869.612  3887.198  3800.350  3800.350\n",
       "8469 2025-08-26  3883.562  3871.471  3888.599  3859.758  3868.382\n",
       "8468 2025-08-25  3825.759  3848.163  3883.562  3839.972  3883.562\n",
       "...         ...       ...       ...       ...       ...       ...\n",
       "4    1990-12-25    114.55   120.090   120.250   114.550   120.250\n",
       "3    1990-12-24    109.13   113.570   114.550   109.130   114.550\n",
       "2    1990-12-21    104.39   109.070   109.130   103.730   109.130\n",
       "1    1990-12-20     99.98   104.300   104.390    99.980   104.390\n",
       "0    1990-12-19              96.050    99.980    95.790    99.980\n",
       "\n",
       "[8473 rows x 6 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按照'Day'列进行降序排列\n",
    "#by=['Day']的意思为指定按照名为‘Day'的列进行排序\n",
    "#ascending=False表示降序排列\n",
    "data = data.sort_values(by=['Day'], axis=0,ascending=False)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method sort_values in module pandas.core.frame:\n",
      "\n",
      "sort_values(\n",
      "    by: 'IndexLabel',\n",
      "    *,\n",
      "    axis: 'Axis' = 0,\n",
      "    ascending: 'bool | list[bool] | tuple[bool, ...]' = True,\n",
      "    inplace: 'bool' = False,\n",
      "    kind: 'SortKind' = 'quicksort',\n",
      "    na_position: 'str' = 'last',\n",
      "    ignore_index: 'bool' = False,\n",
      "    key: 'ValueKeyFunc | None' = None\n",
      ") -> 'DataFrame | None' method of pandas.core.frame.DataFrame instance\n",
      "    Sort by the values along either axis.\n",
      "\n",
      "    Parameters\n",
      "    ----------\n",
      "    by : str or list of str\n",
      "        Name or list of names to sort by.\n",
      "\n",
      "        - if `axis` is 0 or `'index'` then `by` may contain index\n",
      "          levels and/or column labels.\n",
      "        - if `axis` is 1 or `'columns'` then `by` may contain column\n",
      "          levels and/or index labels.\n",
      "    axis : \"{0 or 'index', 1 or 'columns'}\", default 0\n",
      "         Axis to be sorted.\n",
      "    ascending : bool or list of bool, default True\n",
      "         Sort ascending vs. descending. Specify list for multiple sort\n",
      "         orders.  If this is a list of bools, must match the length of\n",
      "         the by.\n",
      "    inplace : bool, default False\n",
      "         If True, perform operation in-place.\n",
      "    kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, default 'quicksort'\n",
      "         Choice of sorting algorithm. See also :func:`numpy.sort` for more\n",
      "         information. `mergesort` and `stable` are the only stable algorithms. For\n",
      "         DataFrames, this option is only applied when sorting on a single\n",
      "         column or label.\n",
      "    na_position : {'first', 'last'}, default 'last'\n",
      "         Puts NaNs at the beginning if `first`; `last` puts NaNs at the\n",
      "         end.\n",
      "    ignore_index : bool, default False\n",
      "         If True, the resulting axis will be labeled 0, 1, …, n - 1.\n",
      "    key : callable, optional\n",
      "        Apply the key function to the values\n",
      "        before sorting. This is similar to the `key` argument in the\n",
      "        builtin :meth:`sorted` function, with the notable difference that\n",
      "        this `key` function should be *vectorized*. It should expect a\n",
      "        ``Series`` and return a Series with the same shape as the input.\n",
      "        It will be applied to each column in `by` independently.\n",
      "\n",
      "    Returns\n",
      "    -------\n",
      "    DataFrame or None\n",
      "        DataFrame with sorted values or None if ``inplace=True``.\n",
      "\n",
      "    See Also\n",
      "    --------\n",
      "    DataFrame.sort_index : Sort a DataFrame by the index.\n",
      "    Series.sort_values : Similar method for a Series.\n",
      "\n",
      "    Examples\n",
      "    --------\n",
      "    >>> df = pd.DataFrame({\n",
      "    ...     'col1': ['A', 'A', 'B', np.nan, 'D', 'C'],\n",
      "    ...     'col2': [2, 1, 9, 8, 7, 4],\n",
      "    ...     'col3': [0, 1, 9, 4, 2, 3],\n",
      "    ...     'col4': ['a', 'B', 'c', 'D', 'e', 'F']\n",
      "    ... })\n",
      "    >>> df\n",
      "      col1  col2  col3 col4\n",
      "    0    A     2     0    a\n",
      "    1    A     1     1    B\n",
      "    2    B     9     9    c\n",
      "    3  NaN     8     4    D\n",
      "    4    D     7     2    e\n",
      "    5    C     4     3    F\n",
      "\n",
      "    Sort by col1\n",
      "\n",
      "    >>> df.sort_values(by=['col1'])\n",
      "      col1  col2  col3 col4\n",
      "    0    A     2     0    a\n",
      "    1    A     1     1    B\n",
      "    2    B     9     9    c\n",
      "    5    C     4     3    F\n",
      "    4    D     7     2    e\n",
      "    3  NaN     8     4    D\n",
      "\n",
      "    Sort by multiple columns\n",
      "\n",
      "    >>> df.sort_values(by=['col1', 'col2'])\n",
      "      col1  col2  col3 col4\n",
      "    1    A     1     1    B\n",
      "    0    A     2     0    a\n",
      "    2    B     9     9    c\n",
      "    5    C     4     3    F\n",
      "    4    D     7     2    e\n",
      "    3  NaN     8     4    D\n",
      "\n",
      "    Sort Descending\n",
      "\n",
      "    >>> df.sort_values(by='col1', ascending=False)\n",
      "      col1  col2  col3 col4\n",
      "    4    D     7     2    e\n",
      "    5    C     4     3    F\n",
      "    2    B     9     9    c\n",
      "    0    A     2     0    a\n",
      "    1    A     1     1    B\n",
      "    3  NaN     8     4    D\n",
      "\n",
      "    Putting NAs first\n",
      "\n",
      "    >>> df.sort_values(by='col1', ascending=False, na_position='first')\n",
      "      col1  col2  col3 col4\n",
      "    3  NaN     8     4    D\n",
      "    4    D     7     2    e\n",
      "    5    C     4     3    F\n",
      "    2    B     9     9    c\n",
      "    0    A     2     0    a\n",
      "    1    A     1     1    B\n",
      "\n",
      "    Sorting with a key function\n",
      "\n",
      "    >>> df.sort_values(by='col4', key=lambda col: col.str.lower())\n",
      "       col1  col2  col3 col4\n",
      "    0    A     2     0    a\n",
      "    1    A     1     1    B\n",
      "    2    B     9     9    c\n",
      "    3  NaN     8     4    D\n",
      "    4    D     7     2    e\n",
      "    5    C     4     3    F\n",
      "\n",
      "    Natural sort with the key argument,\n",
      "    using the `natsort <https://github.com/SethMMorton/natsort>` package.\n",
      "\n",
      "    >>> df = pd.DataFrame({\n",
      "    ...    \"time\": ['0hr', '128hr', '72hr', '48hr', '96hr'],\n",
      "    ...    \"value\": [10, 20, 30, 40, 50]\n",
      "    ... })\n",
      "    >>> df\n",
      "        time  value\n",
      "    0    0hr     10\n",
      "    1  128hr     20\n",
      "    2   72hr     30\n",
      "    3   48hr     40\n",
      "    4   96hr     50\n",
      "    >>> from natsort import index_natsorted\n",
      "    >>> df.sort_values(\n",
      "    ...     by=\"time\",\n",
      "    ...     key=lambda x: np.argsort(index_natsorted(df[\"time\"]))\n",
      "    ... )\n",
      "        time  value\n",
      "    0    0hr     10\n",
      "    3   48hr     40\n",
      "    2   72hr     30\n",
      "    4   96hr     50\n",
      "    1  128hr     20\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 使用help()函数查看sort_values方法的详细帮助信息\n",
    "# help()函数可以显示任何Python对象、函数或方法的文档字符串\n",
    "# 这对于初学者了解函数参数和用法非常有用\n",
    "help(data.sort_values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1990-12-19</td>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1990-12-20</td>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1990-12-21</td>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1990-12-24</td>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1990-12-25</td>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>2025-08-25</td>\n",
       "      <td>3825.759</td>\n",
       "      <td>3848.163</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3839.972</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>2025-08-26</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3871.471</td>\n",
       "      <td>3888.599</td>\n",
       "      <td>3859.758</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>2025-08-27</td>\n",
       "      <td>3868.382</td>\n",
       "      <td>3869.612</td>\n",
       "      <td>3887.198</td>\n",
       "      <td>3800.350</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>2025-08-28</td>\n",
       "      <td>3800.35</td>\n",
       "      <td>3796.711</td>\n",
       "      <td>3845.087</td>\n",
       "      <td>3761.422</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>2025-08-29</td>\n",
       "      <td>3843.597</td>\n",
       "      <td>3842.823</td>\n",
       "      <td>3867.606</td>\n",
       "      <td>3839.206</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Day  Preclose      Open   Highest    Lowest     Close\n",
       "0    1990-12-19              96.050    99.980    95.790    99.980\n",
       "1    1990-12-20     99.98   104.300   104.390    99.980   104.390\n",
       "2    1990-12-21    104.39   109.070   109.130   103.730   109.130\n",
       "3    1990-12-24    109.13   113.570   114.550   109.130   114.550\n",
       "4    1990-12-25    114.55   120.090   120.250   114.550   120.250\n",
       "...         ...       ...       ...       ...       ...       ...\n",
       "8468 2025-08-25  3825.759  3848.163  3883.562  3839.972  3883.562\n",
       "8469 2025-08-26  3883.562  3871.471  3888.599  3859.758  3868.382\n",
       "8470 2025-08-27  3868.382  3869.612  3887.198  3800.350  3800.350\n",
       "8471 2025-08-28   3800.35  3796.711  3845.087  3761.422  3843.597\n",
       "8472 2025-08-29  3843.597  3842.823  3867.606  3839.206  3857.927\n",
       "\n",
       "[8473 rows x 6 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按照'Day'列进行升序排列\n",
    "#by=['Day']的意思为指定按照名为‘Day'的列进行排序\n",
    "#ascending=True表示升序排列\n",
    "data = data.sort_values(by=['Day'],ascending=True)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Day</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1990-12-19</th>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-20</th>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-21</th>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-24</th>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-25</th>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2025-08-25</th>\n",
       "      <td>3825.759</td>\n",
       "      <td>3848.163</td>\n",
       "      <td>3883.562</td>\n",
       "      <td>3839.972</td>\n",
       "      <td>3883.562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2025-08-26</th>\n",
       "      <td>3883.562</td>\n",
       "      <td>3871.471</td>\n",
       "      <td>3888.599</td>\n",
       "      <td>3859.758</td>\n",
       "      <td>3868.382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2025-08-27</th>\n",
       "      <td>3868.382</td>\n",
       "      <td>3869.612</td>\n",
       "      <td>3887.198</td>\n",
       "      <td>3800.350</td>\n",
       "      <td>3800.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2025-08-28</th>\n",
       "      <td>3800.35</td>\n",
       "      <td>3796.711</td>\n",
       "      <td>3845.087</td>\n",
       "      <td>3761.422</td>\n",
       "      <td>3843.597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2025-08-29</th>\n",
       "      <td>3843.597</td>\n",
       "      <td>3842.823</td>\n",
       "      <td>3867.606</td>\n",
       "      <td>3839.206</td>\n",
       "      <td>3857.927</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8473 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Preclose      Open   Highest    Lowest     Close\n",
       "Day                                                         \n",
       "1990-12-19              96.050    99.980    95.790    99.980\n",
       "1990-12-20     99.98   104.300   104.390    99.980   104.390\n",
       "1990-12-21    104.39   109.070   109.130   103.730   109.130\n",
       "1990-12-24    109.13   113.570   114.550   109.130   114.550\n",
       "1990-12-25    114.55   120.090   120.250   114.550   120.250\n",
       "...              ...       ...       ...       ...       ...\n",
       "2025-08-25  3825.759  3848.163  3883.562  3839.972  3883.562\n",
       "2025-08-26  3883.562  3871.471  3888.599  3859.758  3868.382\n",
       "2025-08-27  3868.382  3869.612  3887.198  3800.350  3800.350\n",
       "2025-08-28   3800.35  3796.711  3845.087  3761.422  3843.597\n",
       "2025-08-29  3843.597  3842.823  3867.606  3839.206  3857.927\n",
       "\n",
       "[8473 rows x 5 columns]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将'Day'列设置为数据框的索引\n",
    "#inplace = True表示直接在原数据框data上修改，不需要再赋值给新变量\n",
    "data.set_index('Day', inplace = True)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Day</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1995-12-01</th>\n",
       "      <td>641.14</td>\n",
       "      <td>631.55</td>\n",
       "      <td>639.49</td>\n",
       "      <td>624.93</td>\n",
       "      <td>633.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-12-04</th>\n",
       "      <td>633.81</td>\n",
       "      <td>632.72</td>\n",
       "      <td>635.73</td>\n",
       "      <td>632.24</td>\n",
       "      <td>634.92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-12-05</th>\n",
       "      <td>634.92</td>\n",
       "      <td>636.43</td>\n",
       "      <td>638.76</td>\n",
       "      <td>635.59</td>\n",
       "      <td>637.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-12-06</th>\n",
       "      <td>637.22</td>\n",
       "      <td>637.30</td>\n",
       "      <td>637.32</td>\n",
       "      <td>627.85</td>\n",
       "      <td>628.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-12-07</th>\n",
       "      <td>628.43</td>\n",
       "      <td>628.63</td>\n",
       "      <td>632.37</td>\n",
       "      <td>627.06</td>\n",
       "      <td>631.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-04-24</th>\n",
       "      <td>3710.89</td>\n",
       "      <td>3736.15</td>\n",
       "      <td>3762.39</td>\n",
       "      <td>3689.13</td>\n",
       "      <td>3720.53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-04-25</th>\n",
       "      <td>3720.53</td>\n",
       "      <td>3708.57</td>\n",
       "      <td>3769.25</td>\n",
       "      <td>3653.99</td>\n",
       "      <td>3743.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-04-26</th>\n",
       "      <td>3743.96</td>\n",
       "      <td>3766.48</td>\n",
       "      <td>3784.68</td>\n",
       "      <td>3732.60</td>\n",
       "      <td>3783.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-04-27</th>\n",
       "      <td>3783.06</td>\n",
       "      <td>3788.75</td>\n",
       "      <td>3802.92</td>\n",
       "      <td>3720.60</td>\n",
       "      <td>3759.87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-04-30</th>\n",
       "      <td>3759.87</td>\n",
       "      <td>3784.27</td>\n",
       "      <td>3851.35</td>\n",
       "      <td>3759.48</td>\n",
       "      <td>3841.27</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2757 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           Preclose     Open  Highest   Lowest    Close\n",
       "Day                                                    \n",
       "1995-12-01   641.14   631.55   639.49   624.93   633.81\n",
       "1995-12-04   633.81   632.72   635.73   632.24   634.92\n",
       "1995-12-05   634.92   636.43   638.76   635.59   637.22\n",
       "1995-12-06   637.22   637.30   637.32   627.85   628.43\n",
       "1995-12-07   628.43   628.63   632.37   627.06   631.84\n",
       "...             ...      ...      ...      ...      ...\n",
       "2007-04-24  3710.89  3736.15  3762.39  3689.13  3720.53\n",
       "2007-04-25  3720.53  3708.57  3769.25  3653.99  3743.96\n",
       "2007-04-26  3743.96  3766.48  3784.68  3732.60  3783.06\n",
       "2007-04-27  3783.06  3788.75  3802.92  3720.60  3759.87\n",
       "2007-04-30  3759.87  3784.27  3851.35  3759.48  3841.27\n",
       "\n",
       "[2757 rows x 5 columns]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用时间范围筛选数据，获取1995年12月到2007年4月的数据\n",
    "# 当'Day'列被设置为索引后，可以直接使用日期范围进行筛选\n",
    "data['1995-12':'2007-04']"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py313",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
